package com.example.mvpdemo;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.mvpdemo.mvp5.ILoginView5;
import com.example.mvpdemo.mvp5.LoginPresenter5;
import com.example.mvpdemo.mvp5.base.BaseMvpActivity;


public class MainMvpActivity extends BaseMvpActivity<ILoginView5,LoginPresenter5> implements ILoginView5 {
    private TextView tv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.tv);

    }


    public void clear(View view) {

    }

    @Override
    public void onLoginResult(final String result) {
        tv.setText(result);
    }
//------------------------------------------------------------------------
    //mvp1
    /**

     public void login(View view) {
     presenter=new loginPresenter(this);
     presenter.login("zzh","123");
     }

     */
    //mvp1存在问题：当网络正在进行时，Activity中途退出，UI层引用还在还会回调
    // 解决：presenter绑定与解绑View

//------------------------------------------------------------------------
    //mvp2
    /**

     public void login(View view) {
     presenter = new LoginPresenter2();
     presenter.attachView(this);
     presenter.login("zzh", "123");
     }

     @Override protected void onDestroy() {
     super.onDestroy();
     presenter.detachView(this);
     }

     */
    //mvp2存在问题：如果有多个Presenter，Presenter就会反复的要写绑定解绑方法
    //解决方案：绑定和解绑进行抽象->BasePresenter

//------------------------------------------------------------------------

    //mvp3
    /**

     public void login(View view) {
     presenter = new LoginPresenter3();
     presenter.attachView(this);
     presenter.login("zzh", "123");
     }

     @Override protected void onDestroy() {
     super.onDestroy();
     presenter.detachView(this);
     }

     */
    //mvp3存在问题：抽象的父类BasePresenter类型写死了，里面定义的仅仅是支持ILoginView类型的绑定和解绑
    //解决方案：泛型设计

    //------------------------------------------------------------------------

    //mvp4
    /**

    public void login(View view) {
        presenter = new LoginPresenter4();
        presenter.attachView(this);
        presenter.login("zzh", "123");
    }

    @Override protected void onDestroy() {
        super.onDestroy();
        presenter.detachView(this);
    }

    */
    //mvp4存在问题：随着Activity和Fragment的增加，每一个Activity或Fragment都要反复写绑定和解绑
    //定义一个Activity的抽象类，通过泛型拿到view和presenter自动绑定和解绑

    //---------------------------------------------------------------------------

    //mvp5

    public void login(View view) {
        getPresenter().login("zzh", "123");
    }

    @Override
    public ILoginView5 createView() {
        return this;
    }

    @Override
    public LoginPresenter5 createPresenter() {
        return new LoginPresenter5();
    }

}
